$('document').ready(function(e) {
	//控制分类列表停在浏览器的顶部
	var t = $('#classification-list').offset().top; //获取元素到顶部的距离
	console.log(t);
	$(window).on('scroll', function() {
		var y = $(window).scrollTop();
		console.log(y);
		var u = t - y;
		console.log(u);
		if(u <= 0) {
			$('#classification-list').addClass("gdjt");
			document.getElementById("classification-list2").style.display = "none";
		} else {
			$('#classification-list').removeClass("gdjt");
		}
	});
	//获取到本地存储的账户
	var acc = localStorage.getItem('account', 111111);
	//替换右上角的登录名
	$('#acc').innerHTML = "欢迎，" + acc;
	//分类列表展开和隐藏
	$('#button').on('click', function(e) {
		$('#classification-list2').slideToggle(500);

	});
	//请求分类列表
	$.ajax({
		url: 'http://localhost:8080/second_hand/getType',
		dataType: 'json',
		type: 'get',
		success: function(data) {
			if(data.code === 0) {
				console.log(data);
				for(var i = 0; i < data.data.length; i++) {
					if(i <= 9) {
						var str1 = "<li class='kuang' class='li' value=' "
						+ data.data[i].typeId 
						+ " '><strong> " 
						+ data.data[i].typeName 
						+ " </strong></li>"
						
						$("#list1").append(str1);
						console.log(str1);
					} else {
						var str2 = "<li class='kuang' class='li' value=' "
						+ data.data[i].typeId 
						+ " '><strong> " 
						+ data.data[i].typeName 
						+ " </strong></li>"
						$("#list2").append(str2);
					}
					
				}
				liclick();
			} else {
				alert(data.msg);
			}
		},
		error: function(xhr, type, event) {
			console.log(xhr, type, event);
		}
	});
	//请求商品页
	function liclick(){
		$('li').on('click', function(e) {
			var li = $('ul').val();
			$.ajax({
				url: "http://localhost:8080/second_hand/getGoodsList",
				type: "post",
				dataType: "json",
				data: {
					page: ] ',
					account: acc,
					typeId: li,
				},
				success: function(data) {
					if(data.code === 0) {
	                    alert("请求成功，骗人的");
					} else {
						alert("请求失败");
					}
				},
				error: function(xhr, type, event) {
					console.log(xhr, type, event);
				}
			});
		});
	}
	//分页请求
	
	return false;
});